<%@ page contentType="text/html; charset=utf-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0">
    <title>登录</title>
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" type="text/css" href="/css/sx/login/login.css"/>
    <script src="/js/sx/login/calc.js" type="text/javascript"></script>
</head>

<body>
<div class="outer-layer">
    <!--左边-->
    <div class="content-left">
        <img src="/images/sx/login/logo_icon.png" />
        <img src="/images/sx/login/login_background.png"/>
    </div>
    <!--右边-->
    <div class="content-rigth">
        <div class="content-rigth-title">
            商家管理系统
        </div>
        <div class="content-rigth-form">
            <!--表单-->
            <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
                <div class="form">
<%--                    //TODO 项目发布时候需要删除默认密码--%>
                    <input type="text" id="login" name="login" value="" placeholder="账户" />
                    <input type="password" id="passWord" name="password" value="" placeholder="密码" />
                    <div class="code">
                        <input type="text" id="validCode" name="validCode" placeholder="验证码" />
                        <img onclick="javascript:document.getElementById('codeimage').src='/verifyImg?t=' + Math.random();"
                             id="codeimage" src="/verifyImg" alt="请输入验证码">
                    </div>
                    <input type="submit"  lay-submit lay-filter="login" value="登&nbsp&nbsp&nbsp录" />
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script src="/layuiadmin/layui/layui.js"></script>
<!-- 	<script src="/js/sx/login/jquery3.4.js" type="text/javascript"></script> -->
<!-- 	<script src="/js/sx/login/login.js" type="text/javascript"></script> -->
<script type="text/javascript">
    layui.config({
        base: '../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'user'], function(){
        var $ = layui.$
            ,setter = layui.setter
            ,admin = layui.admin
            ,form = layui.form
            ,router = layui.router()
            ,search = router.search;

        form.render();

        //提交
        form.on('submit(login)', function(obj){
            //请求登入接口
            admin.req({
                url: '/enter' //实际使用请改成服务端真实接口
                ,data: obj.field
                ,done: function(res){
                    if(res.status){
                        //请求成功后，写入 access_token
                        layui.data(setter.tableName, {
                            key: setter.request.tokenName
                            ,value: res.data.access_token
                        });

                        //登入成功的提示与跳转
                        layer.msg('登入成功', {
                            offset: '15px'
                            ,icon: 1
                            ,time: 1000
                        }, function(){
                            location.href = '/business/index'; //后台主页
                        });
                    }else{
     	    		   layer.msg(res.desc, { 
    	    			   offset: '15px'
    	    			   ,icon: 2
    	    			   ,time: 1000
    	    		   });
    	    	   }
                }
            });

        });
    });

</script>
</html>
